package service

import (
	"gorm.io/gorm"
)

type NewTableService struct {
	db *gorm.DB
}

type NewTable struct {
	Name     string
	ID       string
	Describe string
}

func (s *NewTableService) GetTables() []NewTable {
	var rs []NewTable
	rowSql := `
SELECT 
	t.tablename AS Name,
	t.tablename as ID,
	CAST ( obj_description ( c.relfilenode, 'pg_class' ) AS VARCHAR ) AS Describe 
FROM
	pg_tables t 
	LEFT JOIN pg_class c ON t.tablename = c.relname 
WHERE
	schemaname = 'public'
`
	s.db.Raw(rowSql).Scan(&rs)
	return rs
}
